import request from '@/utils/request'

// 查询钓场订单列表
export function listOrder(query) {
  return request({
    url: '/pond/order/list',
    method: 'get',
    params: query
  })
}

// 查询钓场订单详细
export function getOrder(orderId) {
  return request({
    url: '/pond/order/' + orderId,
    method: 'get'
  })
}

// 新增钓场订单
export function addOrder(data) {
  return request({
    url: '/pond/order',
    method: 'post',
    data: data
  })
}

// 修改钓场订单
export function updateOrder(data) {
  return request({
    url: '/pond/order',
    method: 'put',
    data: data
  })
}

// 删除钓场订单
export function delOrder(orderId) {
  return request({
    url: '/pond/order/' + orderId,
    method: 'delete'
  })
}

// 确认签到并生成订单
export function confirmCheckin(data) {
  return request({
    url: '/pond/order/confirmCheckin',
    method: 'post',
    data: data
  })
}

// 直接创建订单（到场用户）
export function createDirectOrder(data) {
  return request({
    url: '/pond/order/createDirect',
    method: 'post',
    data: data
  })
}

// 结算订单
export function settleOrder(data) {
  return request({
    url: '/pond/order/settle',
    method: 'put',
    data: data
  })
}

// 取消订单
export function cancelOrder(orderId, reason) {
  return request({
    url: '/pond/order/cancel/' + orderId,
    method: 'put',
    params: { reason }
  })
}

// 根据用户ID查询订单列表
export function getUserOrders(userId) {
  return request({
    url: '/pond/order/user/' + userId,
    method: 'get'
  })
}

// 用户签到
export function checkinAppointment(appointmentSegmentId) {
  return request({
    url: '/pond/order/checkin',
    method: 'post',
    params: { appointmentSegmentId }
  })
}

// 创建订单（预约签到后自动创建）
export function createFromAppointment(appointmentSegmentId) {
  return request({
    url: '/pond/order/createFromAppointment/' + appointmentSegmentId,
    method: 'post'
  })
}

// 更新订单状态
export function updateOrderStatus(orderId, status) {
  return request({
    url: '/pond/order/' + orderId + '/status/' + status,
    method: 'put'
  })
}

// 完成订单
export function completeOrder(orderId) {
  return request({
    url: '/pond/order/' + orderId + '/complete',
    method: 'put'
  })
}

// 添加订单项
export function addOrderItem(orderId, data) {
  return request({
    url: '/pond/order/' + orderId + '/item',
    method: 'post',
    data: data
  })
}

// 更新订单项支付状态
export function updateItemPayStatus(itemId, payStatus, payType) {
  return request({
    url: '/pond/order/item/' + itemId + '/pay',
    method: 'put',
    params: { payStatus, payType }
  })
}

// 生成订单编号
export function generateOrderNo() {
  return request({
    url: '/pond/order/generateOrderNo',
    method: 'get'
  })
}